package com.ljh.myrpc.registry;

import com.ljh.myrpc.model.ServiceMetaInfo;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RegistryServiceCache {
    Map<String, List<ServiceMetaInfo>> serviceCache = new ConcurrentHashMap<>();

    // 写缓存
    void writeCache(String key, List<ServiceMetaInfo> newServiceCache) {
        if (newServiceCache != null && !newServiceCache.isEmpty()) {
            this.serviceCache.put(key, newServiceCache);
        }
    }

    // 读缓存
    List<ServiceMetaInfo> readCache(String key) {
        if (key == null) {
            return null;
        }
        return this.serviceCache.get(key);
    }

    // 清空缓存
    void clearCache(String servicekey) {
        serviceCache.remove(servicekey);
    }
}
